package action.plan;

import org.springframework.security.context.SecurityContext;
import org.springframework.security.context.SecurityContextHolder;

import persistence.model.TdfkfaUser;
import presentation.PageVO;
import presentation.extendmodel.TdfkfaMainEx;
import service.PlanService;
import service.UserService;

import com.opensymphony.xwork2.ActionSupport;

import constant.ServiceConstants;

public class OwnPlanManageAction extends ActionSupport {

	private static final long serialVersionUID = -180915472152848807L;

	private TdfkfaMainEx main;

	private PlanService planService;

	private UserService userService;

	private PageVO pageVO;

	private String returnCode;

	public String list() throws Exception {

		SecurityContext ctx = SecurityContextHolder.getContext();
		String username = ctx.getAuthentication().getName();
		main = planService.getOwnPlan(username);
		return SUCCESS;
	}

	public String submit() throws Exception {
		SecurityContext ctx = SecurityContextHolder.getContext();
		String username = ctx.getAuthentication().getName();
		TdfkfaUser user = userService.getUserByUsername(username);
		int ret = planService.submitPlan(user.getPlanId());
		if (ret == ServiceConstants.SUCCESS) {
			returnCode = "success";
		} else {
			returnCode = "failure";
		}
		return SUCCESS;
	}

	public PageVO getPageVO() {
		return pageVO;
	}

	public void setPageVO(PageVO pageVO) {
		this.pageVO = pageVO;
	}

	public TdfkfaMainEx getMain() {
		return main;
	}

	public void setPlanService(PlanService planService) {
		this.planService = planService;
	}

	public String getReturnCode() {
		return returnCode;
	}

	public void setUserService(UserService userService) {
		this.userService = userService;
	}

}
